[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 rewind()                Reposition File Pointer to Beginning of Stream

 #include   <stdio.h>

 void       rewind(stream);
 FILE       *stream;                     Pointer to file structure

    rewind() repositions the file pointer associated with 'stream' to the
    beginning of the file.  Rewind() is equivalent to:

                   fseek(stream,0L,SEEK_SET)

    Except it clears both the end-of-file and error indicators; fseek()
    clears only the end-of-file indicator.

       Returns:     0, if successful; non-zero is returned on failure.

   -------------------------------- Example ---------------------------------

    The following statements open a file, save the current file position,
    reposition the file pointer to the beginning of the file, then return
    to the saved position.

           #include <stdio.h>

           FILE *stream;
           long save_pos;

           main()
           {
               if ((stream = fopen("data.txt","r+")) != NULL) {
                    save_pos = ftell(stream);
                    rewind(stream);
                    fseek(stream,save_pos,SEEK_SET);
               }
           }


See Also: fseek() ftell()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson